﻿using BasicData.Application.Input;
using BasicData.Application.Input.Material;
using BasicData.Application.Output;
using BasicData.Application.Services.Material;
using BasicData.Result;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BasicData.Api.Controllers
{
    /// <summary>
    /// 物料群组
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MaterialController : ControllerBase
    {
        IMaterialServices services;
        ILogger<MaterialController> logger;

        public MaterialController(IMaterialServices services, ILogger<MaterialController> logger)
        {
            this.services = services;
            this.logger = logger;
        }
        /// <summary>
        /// 添加物料
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<int> AddMaterial(MaterialInput input)
        {
            logger.LogInformation("添加物料");
            return services.AddMaterial(input);
        }
        /// <summary>
        /// 删除物料
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut]
        public ApiResult<int> DeleteMaterial(long id)
        {
            logger.LogInformation("删除物料");
            return services.DeleteMaterial(id);
        }
        /// <summary>
        /// 获取物料
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiPaging<MaterialOutput> GetMaterial([FromQuery] PageInput input)
        {
            logger.LogInformation("获取物料");
            return services.GetMaterial(input);
        }
        /// <summary>
        /// 修改物料
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public ApiResult<int> UpdateMaterial(UpdateMaterialInput input)
        {
            logger.LogInformation("修改物料");
            return services.UpdateMaterial(input);
        }
    }
}
